home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1998 August / PC Plus SuperCD 50b Issue 142 (CD142b) (August 1998).iso / full / nt / MSSql / I386 / sqlx86.exe / PTK / SAMPLES / OLEAUTO / LOOPBACK.RDO / CSQLRDO.CLS next >
Encoding:
Text File  |  1996-04-03  |  1.9 KB  |  66 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "CSqlRdo"
  6. Attribute VB_Creatable = True
  7. Attribute VB_Exposed = True
  8. Option Explicit
  9.  
  10.  
  11. 'This function uses RDO to call SQL Server and get
  12. 'the contents of the authors table.  It returns
  13. 'a tabular array equivalent to the rowset
  14. 'returned from SQL Server.
  15. '
  16. Public Function RdoGetData(TableName As String, Token As Variant) As Variant
  17.     Dim aRecords As Variant
  18.     Dim cnDatabase As rdoConnection
  19.     Dim rs As rdoResultset
  20.     Dim sConnect As String
  21.     Dim sSQL As String
  22.     Dim iRec As Integer
  23.     
  24.     'Create connection string to SQL Server
  25.     sConnect = "UID=sa;PWD=;DATABASE=pubs"
  26.     
  27.     'The DSN name in this sample is named PUBS; when setting up the ODBC driver for this
  28.     'Data Source, the checkbox "Generate Stored Procedure for Prepared Statement"
  29.     'should NOT be checked
  30.     Set cnDatabase = rdoEngine.rdoEnvironments(0).OpenConnection(dsname:="pubs", _
  31.                                                                  Prompt:=rdDriverNoPrompt, _
  32.                                                                  Connect:=sConnect)
  33.     
  34.     'Bind the extended procedure to the client session
  35.     sSQL = "exec sp_bindsession '" + Token + "'"
  36.     cnDatabase.Execute sSQL, rdExecDirect
  37.     
  38.     'Set the SQL statement to run
  39.     sSQL = "Select * from " + TableName
  40.     Set rs = cnDatabase.OpenResultset(Name:=sSQL, Type:=rdOpenStatic)
  41.     
  42.     'Move to last record in order to count how many
  43.     'records are in the result set.  Then, adjust the
  44.     'array to contain the proper number of rows.
  45.     With rs
  46.         .MoveLast
  47.         .MoveFirst
  48.     End With
  49.     
  50.     'Copy the whole recordset into a variant
  51.     aRecords = rs.GetRows(rs.RowCount)
  52.     
  53.     'Close resultset
  54.     rs.Close
  55.     
  56.     'Close db connection
  57.     cnDatabase.Close
  58.     
  59.     'Return the recordset to the caller as a variant
  60.     RdoGetData = aRecords
  61.  
  62. End Function
  63.  
  64.  
  65.  
  66.